package org.dubnation.base.excel.upload.util;

import org.dubnation.base.annotation.SexJustManAndWoman;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 自定义校验注解@SexJustManAndWoman的实现类
 **/
public class SexJustManAndWomanImpl implements ConstraintValidator<SexJustManAndWoman, String> {
    String man;
    String woman;

    @Override
    public void initialize(SexJustManAndWoman constraintAnnotation) {
        man = constraintAnnotation.man();
        woman = constraintAnnotation.woman();
    }

    @Override
    public boolean isValid(String sex, ConstraintValidatorContext constraintValidatorContext) {
        if (sex.equals(null)){
            return false;
        }
        return (sex.equals(man) || sex.equals(woman));
    }
}
